Specright Specification to Product System API
Error Codes
Specright Specification to Product System API data validation will be composed of the error handling mechanism where the user and Api owner is notified as soon as something is wrong.
This API uses conventional HTTP response codes to indicate the success or failure of an API request.
In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required field was omitted). Codes in the 5xx range indicate an error with the server.
HTTP Status Code Summary
| Status Code | Description |
|---|---|
| 200 | Success / OK |
| 201 | Created |
| 204 | No Content |
| 400 | Bad Request The server could not understand the request due to invalid syntax. |
| 401 | Unauthorized Invalid token. The server was unable to authenticate the user. |
| 403 | Forbidden |
| 404 | Not Found |
| 405 | Method Not Allowed |
| 412 | Precondition Failed Failed updating resource due to invalid If-Match. |
| 415 | Unsupported Media Type The media format of the requested data is not supported by the server. |
| 428 | Precondition Required Required header 'If-Match' not provided. |
| 500 | Internal Server Error An internal server error was observed. |
| 502 | Bad Gateway The server encountered received an invalid response from an inbound server it accessed while attempting to fulfil the request. |
| 503 | Service Unavailable The server was unable to handle the request due to a temporary overloading or maintenance of the server. |
| 504 | Gateway Timeout |
Business Error Handling
In our API, we handle business errors using specific error codes to identify and manage different scenarios. Below are some common business error codes:
Illustrative examples -
- BUSINESS_VALIDATION_ERROR: This error occurs when a business rule is violated.
- Error Code:
BUSINESS_VALIDATION_ERROR - Description: The provided data does not meet the business validation criteria.
- Example:{"errorCode": "BUSINESS_VALIDATION_ERROR","message": "The age must be less than 30."}
- Error Code:
- INSUFFICIENT_FUNDS: This error occurs when an account does not have enough funds to complete a transaction.
- Error Code:
INSUFFICIENT_FUNDS - Description: The account balance is insufficient for the requested operation.
- Example:{"errorCode": "INSUFFICIENT_FUNDS","message": "Your account does not have enough funds to complete this transaction."}
- Error Code:
- ENTITY_NOT_FOUND: This error occurs when a requested entity is not found in the system.
- Error Code:
ENTITY_NOT_FOUND - Description: The requested entity does not exist.
- Example:{"errorCode": "ENTITY_NOT_FOUND","message": "The user with ID 12345 was not found."}
- Error Code:
Error Handling Approach
Our API several error handling strategies to ensure robustness and reliability.
Custom Policies for Error Scenarios
Illustrative examples -
Retry Mechanism
We implement a retry mechanism to handle transient errors, such as temporary network issues. This mechanism retries the operation a specified number of times before failing.
Example:
retry:
count: 3
interval: 2000 # in milliseconds